#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Description  : 
Author       : Keyman
Date         : 2021-06-24 09:50:22
LastEditors  : Keyman
LastEditTime : 2021-06-24 10:09:14
"""

from collections.abc import Iterable
from typing import List, Union

class Vector:
    """
    Represent a vector in multidimensional space
    """
    def __init__(self, d: Union[int, Iterable]):
        """
        Create d-dimensional vector of zeros
        可接受任何形式的参数构造一个
        :param d: 
        :return : 
        """
        try:
            if isinstance(d, int):
                self._coords = [0] * d
            elif isinstance(d, float):
                d = int(d)
                self._coords = [0] * d
        else:
            if not isinstance(d, Iterable):
                raise ValueError("d must be integer or iterable object")
            self._coords = [0] * len(d)
            for index in range(len(d)):
                self._coords[index] = d[index]
        except ValueError:
            raise ValueError("d must be integer or iterable object")


    
    def __len__(self):
        """
        Return the dimensions of the vector
        """
        return len(self._coords)

    def __getitem__(self, j: int):
        """Return the jth coordinate of the vector"""
        return self._coords[j]

    def __setitem__(self, j: int, val: int):
        """Set the jth coordinate of the vector to given value"""
        if not isinstance(val, int):
            raise ValueError("Value must be an integer")
        return self._coords[j] = val

    def __add__(self, other: List):
        """Return sum of two vectors"""
        if len(self) != len(other):
            raise ValueError("dimensions must agree")
        result = Vector(len(self))
        for index in range(len(other)):
            result[index] = self[index] + other[index]
        return result


    def __eq__(self, other: List):
        """Return True if two vector has same coordinates as other"""
        return self._coords == other._coords

    def __ne__(self, other: List):
        """Return True if two vector differs from other"""
        return not self == other

    def __str__(self):
        return '<' + str(self._coords)[1:-1] + '>'  # adapt list representation

    def __mul__(self, other: List):
        
        pass